//判断文件是否存在
require(["layuiall", "helper"], function (layui) {
    layui.use("hxNav", function () {
        menu();
        //刷新页面
        $("#refIframe").click(function () {
            layer.load(0, {
                time: 500,
                end:function () {
                    var $currentIframe = $("#layui-body iframe:visible");
                    //$currentIframe.attr("src",$currentIframe.attr("src"));
                    $currentIframe[0].contentWindow.location.reload();
                    return false;
                }
            });
        })
        //刷新后台菜单
        $("a.refmenu").click(function () {
            $.ajax({
                type:'get',
                url:"/admin/system.menu/getMenu",
                dataType:'json',
                data:{
                    refMenu:1
                },
                success:function (res) {
                    $("#hxNavbar").html('')
                    menu()
                }
            })
        })
    })
    function menu() {
        layui.hxNav({
            element: '#hxNavbar',
            url:CONFIG.MENU_URL,
            type: 'post',
            shrink: false,
            onSelect: function (v)
            {
                if(v){
                    if (  v.href && v.hasView ==1 ) {
                        var laods = layer.load(0, {
                            shade:0.5
                        });
                        var iframe = $("#layui-body");
                        if(  iframe.find("#iframe").attr("src")==v.href){
                            //return false
                        }
                        iframe.find("#iframe").attr({"src": v.href});
                        localStorage.setItem("url_link", JSON.stringify({
                            id:v.id,
                            url:v.href
                        }));
                        add_url(v.href);
                        document.getElementById("iframe").onload = function() {
                            layer.close(laods)
                        }
                    }
                }
            },
            success:function () {
                var loca =  localStorage.getItem("url_link");
                if(loca){
                    loca = JSON.parse(loca);
                    layui.hxNav('select',loca.id );
                  // $("#layui-body").find("#iframe").attr({"src": loca.url});
                }
            }
        });
    }

});



